home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / dll_gen / loads / common / acaglbl.bas next >
BASIC Source File  |  1996-01-12  |  7KB  |  258 lines

  1. Option Explicit
  2. ' =========================================================================================
  3. ' Standard Global String Variables
  4. ' =========================================================================================
  5. Global gsCRLF As String         ' Carriage-Return Line-Feed character
  6. Global gsTAB As String          ' Standard TAB character
  7.  
  8. ' ===============================================================
  9. ' Declaration of Application Title
  10. ' ===============================================================
  11. Global TITLE As String ' Setup at start of application as several apps share code can't be Global Constant
  12.  
  13. ' ========================================================================================
  14. ' Global Constant Values
  15. ' ========================================================================================
  16. Global Const INI_ERROR = "ERROR"
  17.  
  18. Function AddAmpersand (msg As Variant) As String
  19.     
  20. On Error GoTo AddAmpersand_Err
  21.  
  22.     Dim iPos As Integer
  23.     Dim strStart As String, strEnd As String
  24.     
  25.     iPos = InStr(msg, "&")
  26.  
  27.     If iPos <> 0 Then
  28.         strStart = Left$(msg, iPos)
  29.         strEnd = Right$(msg, Len(msg) - iPos)
  30.         AddAmpersand = strStart & "&" & strEnd
  31.     Else
  32.         AddAmpersand = msg
  33.     End If
  34.     
  35.     Exit Function
  36.  
  37. AddAmpersand_Err:
  38.     AddAmpersand = ""
  39.     Exit Function
  40.  
  41. End Function
  42.  
  43. ' Centres form in argument on the screen
  44. Sub CentreMe (frmLoadingForm As Form)
  45. ' mh 951012 - added checking for MDI child window
  46.  
  47.         frmLoadingForm.Move (screen.Width - frmLoadingForm.Width) / 2, (screen.Height - frmLoadingForm.Height) / 2
  48.     
  49. End Sub
  50.  
  51. Function CheckField (vFieldIn) As Variant
  52.  
  53.     If Not IsNull(vFieldIn) Then CheckField = vFieldIn
  54.  
  55. End Function
  56.  
  57. ' Validates a date as a string dd/mm/yy and returns true/false
  58. Function DateValid (sTestDate As String)
  59.  
  60.     Dim RetDate
  61.  
  62. On Error GoTo InvalidDate
  63.  
  64.     ' The DateValue function returns an error if the date is not valid
  65.     ' It tests for silly numbers - eg. "101010" passed in as a string
  66.     ' It tests for close numbers - eg. "32/03/95" or "15/13/95"
  67.     ' It also tests for leap years
  68.  
  69.     RetDate = DateValue(sTestDate)
  70.  
  71.     DateValid = True
  72.     Exit Function
  73.  
  74. InvalidDate:
  75.     DateValid = False
  76.     Exit Function
  77.  
  78. End Function
  79.  
  80. Function dMax (dA As Double, dB As Double) As Double
  81. ' rdm 950722
  82. ' return the Max value
  83.  
  84.     If dA > dB Then
  85.         dMax = dA
  86.     Else
  87.         dMax = dB
  88.     End If
  89.  
  90. End Function
  91.  
  92. Function dMin (dA As Double, dB As Double) As Double
  93. ' rdm 950722
  94. ' return the Min value
  95.  
  96.     If dA < dB Then
  97.         dMin = dA
  98.     Else
  99.         dMin = dB
  100.     End If
  101.  
  102. End Function
  103.  
  104. ' Subroutine used to display error messages in VB code
  105. Sub ErrorHandler (iErr As Integer, lErrLine As Long, sModule As String, sFunction As String)
  106. ' Displays Error Message Box
  107.  
  108.     MsgBox "Error " & iErr & ": " & Error & "." & gsCRLF & "In Line " & lErrLine & gsCRLF + gsCRLF + "Module : " + sModule + gsCRLF + gsCRLF + " Function : " + sFunction, 64, TITLE
  109. ' Format of error handling :
  110.  
  111. ' sub FunctionName()
  112.  
  113.     ' On Error Goto FunctionNameError     ' Use function name with error written after it
  114.     '
  115.     '
  116.     ' ..... Body of function
  117.     '
  118.     '
  119.     ' Exit Sub
  120.     
  121. ' FunctionNameError:
  122.     ' Call ErrorHandler(Err, Erl, ModuleName, FunctionName)
  123.     ' Exit Sub
  124.  
  125.     ' End Sub
  126.  
  127.     '
  128.     '
  129.     ' The ModuleName above is the name of the VB module the error occured
  130.     ' i.e. "GLOBALS.BAS"
  131.     ' The FunctionName is the name of the VB function that the error occured in i.e. "ErrorHandler"
  132.     
  133. End Sub
  134.  
  135. Function FindAndReplace (sFind As String, sReplace As String, sCurrentString As String) As String
  136. On Error GoTo FindAndReplaceError
  137.  
  138.     Dim sNewString As String
  139.     Dim sTempString As String
  140.     Dim iPos As Integer
  141.  
  142.     ' look for a SPACE
  143.     iPos = InStr(sCurrentString, sFind)
  144.  
  145.     ' loop While there are SPACES in CurrentString
  146.     Do While iPos
  147.     sTempString = Left$(sCurrentString, iPos)
  148.     sNewString = sNewString & Left$(sTempString, iPos - 1) & sReplace
  149.     sCurrentString = Right$(sCurrentString, Len(sCurrentString) - iPos)
  150.     iPos = InStr(sCurrentString, sFind)
  151.     Loop
  152.  
  153.     ' capitalise the last word n current string
  154.     If Len(sCurrentString) Then
  155.     sNewString = sNewString & sCurrentString
  156.     End If
  157.  
  158.     FindAndReplace = sNewString
  159.     Exit Function
  160.  
  161. FindAndReplaceError:
  162.     'Call ErrorHandler(Err, Erl, "WBLIST", "FindAndReplace")
  163.     Exit Function
  164.  
  165. End Function
  166.  
  167. ' Overload of the ReadFileInI function that allows you to specify the INI file name
  168. Function GetINIStringValue (sSection$, sKeyName$, sDefaultValue$, sFileName$) As String
  169.  
  170.     Dim iStrLen As Integer
  171.     Dim sString As String * 150
  172.     
  173.     iStrLen = GetPrivateProfileString(sSection, sKeyName, sDefaultValue$, sString, Len(sString), sFileName$)
  174.     GetINIStringValue = Left(sString, iStrLen)
  175.     
  176. End Function
  177.  
  178. Function iMin (a As Integer, b As Integer) As Integer
  179.  
  180.     If a < b Then
  181.         iMin = a
  182.     Else
  183.         iMin = b
  184.     End If
  185.  
  186. End Function
  187.  
  188. Sub SetINIStringValue (sSection As String, sEntry As String, sNewValue As String, sINIFile As String)
  189.     Dim iRetValue As Integer
  190.     
  191.     '// write appropriate information to ini file
  192.     iRetValue = WritePrivateProfileString(sSection, sEntry, sNewValue, sINIFile)
  193.     
  194. End Sub
  195.  
  196. ' Sets up any global variables for this program
  197. Sub SetupGlobalVariables ()
  198.     
  199.     gsCRLF = Chr$(13) + Chr$(10)    ' Used to store the carriage return string
  200.     gsTAB = Chr$(9)
  201.     
  202. End Sub
  203.  
  204. Function SLDate (sDate As String) As String
  205. ' rdm 950524
  206.  
  207. ' take date in  medium format convert to YYYYMMDD
  208. On Error GoTo SLDate_Err
  209.     
  210.     SLDate = (Format$(DateValue(sDate), "YYYY") + Format$(DateValue(sDate), "MM") + Format$(DateValue(sDate), "DD"))
  211.     Exit Function
  212.  
  213. SLDate_Err:
  214.     'SLDate = "00000000" - previously in ACAGLBL.BAS
  215.     SLDate = ""
  216.     Exit Function
  217.  
  218. End Function
  219.  
  220. Function sMax (a As Single, b As Single) As Single
  221.  
  222.     If a > b Then
  223.         sMax = a
  224.     Else
  225.         sMax = b
  226.     End If
  227.  
  228. End Function
  229.  
  230. Function sZeroSpaces (sString As String) As String
  231.  
  232. Dim sOut As String
  233. Dim iCount As Integer
  234. Dim iLength As Integer
  235.  
  236. On Error GoTo BadZeroSpaces
  237.     
  238.     sOut = sString
  239.  
  240.     iLength = Len(sOut)
  241.  
  242.     For iCount = 1 To iLength
  243.  
  244.         If Not IsNumeric(Mid(sOut, iCount, 1)) Then Mid(sOut, iCount, 1) = "0"
  245.  
  246.     Next iCount
  247.  
  248.     sZeroSpaces = sOut
  249.     Exit Function
  250.  
  251. BadZeroSpaces:
  252.  
  253.     sZeroSpaces = sString
  254.     Exit Function
  255.  
  256. End Function
  257.  
  258.